
import React, { useEffect, useState } from 'react'
import PubSub from 'pubsub-js'

export default function Didi() {
  
  const [car, setCar] = useState("八手奥迪")

  //在组件初始化时订阅一次
  useEffect(()=>{
    // PubSub.subscribe("qiche",(b,c)=>{ 
    //   // qiche 一手雅迪 undefined
    //   console.log(b,c);
      
    //   setCar(c)
    // })
    // qiche  订阅标识
    PubSub.subscribe("qiche",(_,data)=>{ 
      // qiche 一手雅迪 undefined
      console.log(_,data);
      
      setCar(data)
    })
  },[])

  
  return (
    <div>
      <h2>我是弟弟 我开我哥的{car}</h2>
    </div>
  )
}

